<?php

namespace app\common\model;

use think\Model;

/**
 * Class Auth
 * @package app\common\model
 * 后台操作日志表
 */
class trOperateLog extends Model
{
    protected $pk = 'id';
    protected $resultSetType = 'collection'; //申明结果集是数据集对象（collection），查询结果才能用toArray()方法转为数组
    protected $name = "operate_log"; //表名

    protected $type = [
        'createTime'  =>  'timestamp:Y-m-d H:i'
    ];

    //保存日志
    public static function saveLog($data){
        if(!isset($data['create_time']))
            $data['create_time'] = time();
        $data["mall_id"] = request()->mallData["id"];
        $res = self::create($data);
        if(!$res){
            return false;
        }

        return true;
    }

    //分页获取所有字段数据
    public static function getListByPaginate($filter = [], $page = 1, $limit = 10, $order = "create_time desc"){
        $data = self::where($filter)
            ->order($order)
            ->paginate(array('page' => $page, 'list_rows' => $limit));
        if($data){
            $data = $data->toArray();
            return $data;
        }
        return [];
    }

    public static function delByFilter($where){
        $result = self::where($where)->delete();
        return $result;
    }
}